from filter import *
from image import *
import os

def save_image(image, filename, output_dir='./result'):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    output_path = os.path.join(output_dir, filename)
    cv2.imwrite(output_path, image)
    print(f"图片已保存到: {output_path}")

# 创建不同滤镜
cutout = CutoutFilter()
blur = BlurFilter()
sharpen = SharpenFilter()
texture = TextureFilter()
canny = CannyFilter()

# 测试JPG格式
jpg_image = JPGFormat(cutout)
print("Processing JPG with Cutout filter...")
processed_jpg = jpg_image.process_image('./imgs/girl.jpg')
save_image(processed_jpg, 'girl_cutout.jpg')

jpg_image.set_filter(sharpen)
print("Processing JPG with Sharpen filter...")
processed_jpg_sharp = jpg_image.process_image('./imgs/girl.jpg')
save_image(processed_jpg_sharp, 'girl_sharpen.jpg')

# 测试GIF格式
gif_image = GIFFormat(blur)
print("Processing GIF with Blur filter...")
processed_gif_frames = gif_image.process_image('./imgs/girl.gif')
for i, frame in enumerate(processed_gif_frames[:5]):  # 只保存前5帧作为示例
    save_image(frame, f'girl_blur_{i}.jpg')

# 测试BMP格式
bmp_image = BMPFormat(canny)
print("Processing BMP with Canny filter...")
processed_bmp = bmp_image.process_image('./imgs/girl.bmp')
save_image(processed_bmp, 'girl_canny.bmp')
